<template>
    <div class="ready-exam">
        <el-alert title="点击~开始考试后将白动进入考试,请诚信考试!" type="error">
        </el-alert>
        <el-card class="box-card">
            <div class="text"> <b>考试名称: </b> <span>{{ exam_name }}</span></div>
            <div class="text"> <b>考试时长: </b> <span>{{ exam_time }}分钟</span></div>
            <div class="text"> <b>考试总分: </b> <span>{{ exam_fullcredit }}分</span></div>
            <div class="text"> <b>及格分数: </b> <span>{{ exam_passline }}分</span></div>
            <div class="text"> <b>考试描述: </b> <span>{{ exam_limit }}</span></div>
            <div class="text"> <b>开放类型: </b> <span>{{ exam_type }}</span></div>
        </el-card>
        <div style="margin-top:10px;">
            <el-button type="primary" @click="jumpToExamination">
                <i class="el-icon-caret-right"></i>
                <span> 点击开始考试 </span>
            </el-button>
            <el-button type="default" @click="goBack">返回</el-button>
        </div>
    </div>
</template>

<script>
import { examDetail } from '../../api/index';
// {exam_name,exam_limit,exam_time,exam_type,exam_fullcredit,exam_passline,topic_lib_id}
export default {
    data() {
        return {
            exam_name: "",
            exam_limit: "",
            exam_time: 30,
            exam_type: "开放",
            exam_fullcredit: 100,
            exam_passline: 60,
            topic_lib_id: "",
            exam_id: "",
        }
    },
    watch: {
        $route: {
            deep: true,
            // immediate: true,
            handler(val) {
                let id = val.query.topic_lib_id;
                this.getExamInfo(id);
            }
        }
    },
    mounted() {
        let id = this.$route.query.topic_lib_id;
        this.exam_id = this.$route.query.exam_id;
        this.getExamInfo(id);
    },
    methods: {
        // 获取考试信息
        getExamInfo(topic_lib_id) {
            examDetail({ topic_lib_id }).then(content => {
                // console.log('题库/考试信息：',content)
                if(content.code == 200){
                    // 整合数据以及渲染
                    this.exam_name = content.result[0].exam_name
                    this.exam_limit = content.result[0].exam_limit
                    this.exam_time = content.result[0].exam_time
                    this.exam_type = content.result[0].exam_type
                    this.exam_fullcredit = content.result[0].exam_fullcredit
                    this.exam_passline = content.result[0].exam_passline
                    this.topic_lib_id = content.result[0].topic_lib_id
                }
            })
                .catch(err => console.log(err))
        },
        // 跳转考试页
        jumpToExamination() {
            this.$router.push({
                path: '/examination',
                query: {
                    topic_lib_id: this.topic_lib_id,
                    exam_id: this.exam_id,
                }
            })
        },
        // 返回上一页
        goBack() {
            this.$router.go(-1);
        }
    }
}

</script>
<style>
.ready-exam .text {
    padding: 10px 0;
    font-size: 15px;
}
</style>